package com.baimawangzi.recovery.servlet.goods;

import com.baimawangzi.recovery.bean.Goods;
import com.baimawangzi.recovery.service.impl.GoodsServiveImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;

@WebServlet("/goodsupdate.do")
public class GoodUpdateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        GoodsServiveImpl goodsServive = new GoodsServiveImpl();
        //解析url参数
        String sid=req.getParameter("id");
        String goodname=req.getParameter("goodname");
        String catename=req.getParameter("catename");
        String sprice=req.getParameter("price");
        String username=req.getParameter("username");
        //造对象
        Goods goods = new Goods(Integer.parseInt(sid), goodname, catename, new BigDecimal(sprice), username);

        int a = goodsServive.update(goods);
        if(a>0){//返回的信息
            req.setAttribute("msg","修改回收物成功");
        }
        else {
            req.setAttribute("msg","修改回收物失败");
        }
        req.getRequestDispatcher("goodslist.do").forward(req,resp);
    }
}
